package com.asia5b.a5mall.middleware.config

import android.text.method.HideReturnsTransformationMethod
import android.text.method.PasswordTransformationMethod
import android.widget.ImageView
import android.widget.TextView
import com.alibaba.android.arouter.launcher.ARouter
import com.asia5b.a5bmall.resource.ActCons
import com.asia5b.a5bmall.resource.ResColor
import com.asia5b.a5bmall.resource.ResString
import com.asia5b.a5mall.middleware.R
import com.asia5b.a5mall.middleware.utils.StringUtils

/**
 * Created by zhangyuncai on 2020/6/11.
 * 超链接管理
 */
object LinkUtils {
    fun setLinkContent(type: LinkType, textView: TextView) {
        when (type) {
            LinkType.LOGIN -> {
                val agreeName = ResString.get(R.string.A5BMall使用协议)
                val agreeHeader = "${ResString.get(R.string.点击按钮即代表您已同意)}${agreeName}"
                val blueColor = ResColor.getBlue()
                StringUtils.setLinkText(agreeHeader, agreeName, textView, blueColor) {
                    ARouter.getInstance()
                            .build(ActCons.WebActivity)
                            .withString("title", ResString.get(R.string.A5BMall使用协议))
                            .withString("url", "https://a5bmall.com/help/102")
                            .navigation()
                }
            }
        }
    }

    /**
     * 设置眼睛打开关闭状态
     */
    fun setEytState(eyeImageView: ImageView,targetTextView:TextView) {
        eyeImageView.setOnClickListener {
            if (targetTextView.transformationMethod is PasswordTransformationMethod) {
                targetTextView.transformationMethod = HideReturnsTransformationMethod.getInstance()
                eyeImageView.setImageResource(R.drawable.ic_eye_close)
                eyeImageView.requestFocus()
            } else {
                targetTextView.transformationMethod = PasswordTransformationMethod.getInstance()
                eyeImageView.setImageResource(R.drawable.ic_eye)
                eyeImageView.requestFocus()
            }
        }
    }
}

